home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / looking.com / LOOKING!.C < prev   
Encoding:
Text File  |  1991-05-26  |  4.7 KB  |  172 lines

  1.  
  2.  
  3.      SUPER-SIMPLE FILE SEARCHING !!
  4.  
  5.  
  6.    This program was designed to be smaller than the incredibly large file-finders
  7. currently available in the Shareware market.  Although it does not scan inside
  8. compressed files, it does search within hidden directories, and successfully
  9. locates hidden, system, and read-only files.
  10.  
  11.    This was written on May 26, 1991 with Turbo C++ Professional package.
  12.  
  13.    It is freeware.  You are free to distribute the code as you like, or use
  14. it as a SHELL for a more complicated, exhaustive searching utility.  My
  15. purpose for releasing the code is to give beginning programmers a guide for
  16. ENTIRE-DISK functioning.
  17.  
  18.          (Compiled with: TCC -ms lookin whooper.asm)
  19.  
  20.  
  21.    Add-on "C" coding could provide:
  22.  
  23.    1) Searching tools that cover all disk drives available, and look inside
  24.       compressed files.
  25.  
  26.    2) Global file execution.
  27.  
  28.    3) Disk-wide text searching.
  29.  
  30.    4) Directory Listing.
  31.  
  32.    5) Quick-directory changers.
  33.  
  34.    6) File-spec searches.
  35.  
  36.  and many MORE, limited only to programming imagination (and God knows that's unlimited!!).
  37.  
  38.  
  39.    If you make improvements on this code, please let me know !!  I love to learn
  40.  new utilities, and always learn A LOT from seeing healthy "C" coding ...
  41.  
  42.  
  43.          DAVE SMITH
  44.  
  45.     Compuserve 71441,2723
  46.  
  47.  
  48.  
  49.  
  50.  
  51. ===================================================================================
  52.  
  53. #include <dos.h>
  54. #include <string.h>               /* SET-UP FOR PROGRAM */
  55. #include <stdio.h>
  56. #include <dir.h>
  57.  
  58. void lookinpath(void);            /* FUNCTION CALLED RECURSIVELY UNTIL ALL PATHS ARE FOUND */
  59.  
  60. extern Whooper(void);             /* EXTERNAL ASSEMBLY PROGRAM FOR WHOOPING SOUND */
  61.  
  62. char file[20];           /* Holds part-name or full filename for search */
  63. char curdir[15];         /* Current directory while searching */
  64.  
  65. int a=0;                 /* Counts # of files found.  Mainly used to determine */
  66.                          /* whether or not a file-match was located */
  67.  
  68. void main(int argc, char *argv[])
  69. {
  70.  
  71. char camefrom[30];       /* Original starting directory */
  72.  
  73. if(argc < 2){ printf("\nUsage: LOOKIN [filename/partname]\n"); exit(0); }
  74.  
  75.  
  76.   /* FILENAME IS COPIED INTO "file" THEN UPPER-CASED */
  77.  
  78. strcpy(file,argv[1]);
  79. strupr(file);
  80.  
  81.  
  82.   /* GET DIRECTORY WE ARE IN, CHANGE INTO ROOT, THEN CALL DIRECTORY-SEARCH FUNCTION */
  83.  
  84. getcurdir(0,camefrom);
  85.  
  86. chdir("\\");
  87. lookinpath();
  88.  
  89.  
  90.   /* CHANGE BACK TO WHERE WE STARTED AND SHOW RESULTS */
  91.  
  92. chdir(camefrom);
  93.  
  94. if(a==0) printf("\nNo match found──",file);
  95. printf("\n");
  96.  
  97. Whooper();
  98. exit(0);
  99.  
  100. }
  101.  
  102. void lookinpath(void)
  103. {
  104.  
  105. int found;
  106. struct ffblk dave;
  107.  
  108. /**  FIND ALL FILES IN DIRECTORY, THEN FIND FIRST OCCURANCE OF THE STRING
  109.  **
  110.  **                  SPECIFIED ON COMMAND LINE.
  111.  **/
  112.  
  113. found=findfirst("*.*",&dave,47);
  114. while(!found)
  115.   {
  116.  
  117.  if(strstr(dave.ff_name,file))
  118.    {
  119.    strcat(dave.ff_name,"$");     /* Setup for DOS function call                  */
  120.    strcat(curdir,"$");
  121.  
  122.    r.h.ah=0x09;                  /* I utilize the function call for the          */
  123.    r.x.dx=FP_OFF("Found-$");    /* simple fact that Printf() is slow, bulky     */
  124.    s.ds=FP_SEG("Found-$");      /* and looks "draggy" in faster coding          */
  125.    intdosx(&r,&r,&s);            /*                                              */
  126.                                  /* I use the printf() call below, because       */
  127.    r.x.dx=FP_OFF(dave.ff_name);  /* my main information is printed and           */
  128.    s.ds=FP_SEG(dave.ff_name);    /* I can relax my output by that time           */
  129.    intdosx(&r,&r,&s);            /*                                              */
  130.                  /* Beginners might want to use:                 */
  131.    r.x.dx=FP_OFF("  ═══$");     /* Printf("Found-%s═══%s",dave.ff_name,curdir)*/
  132.    s.ds=FP_SEG("  ═══$");
  133.    intdosx(&r,&r,&s);
  134.  
  135.    r.x.dx=FP_OFF(curdir);
  136.    s.ds=FP_SEG(curdir);
  137.    intdosx(&r,&r,&s);
  138.  
  139.    printf("\n");                  /* Throw a line-feed in */
  140.     a++;
  141.    }
  142.  
  143.  found=findnext(&dave);
  144.   }
  145.  
  146.  
  147.   /* ONCE ALL FILES ARE SEARCHED, LOOK INTO ALL DIRECTORIES */
  148.  
  149. found=findfirst("*.*",&dave,FA_DIREC+FA_SYSTEM+FA_HIDDEN);
  150. while(!found)
  151.  {
  152.  
  153.  if(((dave.ff_attrib & FA_DIREC)==FA_DIREC)&&(dave.ff_name[0] !='.'))
  154.   {
  155.  
  156.    strcpy(curdir,dave.ff_name);
  157.  
  158.    chdir(dave.ff_name); /* Change into newly found directory */
  159.  
  160.    lookinpath();        /* <------Function called recursively */
  161.  
  162.    chdir("..");         /* Once all possible directories here have been  */
  163.                         /* exhausted, go up one and continue with other  */
  164.                         /*              recursive calls.                 */
  165.  
  166.   }
  167.  found=findnext(&dave);
  168.  }
  169.  
  170. }
  171.  
  172.